package org.fengling.readingplatform.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.fengling.readingplatform.manager.mapper.AuthorMapper;
import org.fengling.readingplatform.manager.service.AuthorService;
import org.fengling.readingplatform.model.dto.author.AuthorDto;
import org.fengling.readingplatform.model.entity.author.Author;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthorServiceImpl implements AuthorService {

    @Autowired
    private AuthorMapper authorMapper;

    // 作家分页查询方式
    @Override
    public PageInfo<Author> findByPage(Integer pageNum, Integer pageSize, AuthorDto authorDto) {
        PageHelper.startPage(pageNum,pageSize);
        List<Author> list = authorMapper.findByPage(authorDto);
        PageInfo<Author> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    // 作家删除方式
    @Override
    public void deleteById(Long authorId) {
        authorMapper.delete(authorId);
    }

    // 作家添加方法
    @Override
    public void saveAuthor(Author author) {
        authorMapper.save(author);
    }

    // 作家更新方法
    @Override
    public void updateAuthor(Author author) {
        authorMapper.update(author);
    }

}
